#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=2005;

int n;
ll a[N],f[N][N];
// f[i][j]: one color ends with i, another color ends with j

template<typename T>
    inline T max_eq(T &x,T y){
        return x= x>y? x:y;
    }

void solve(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%lld",&a[i]);
    memset(f,0,sizeof(f));
    f[1][0]=0;
    for(int i=2;i<=n;++i){
        for(int j=0;j<=i-1;++j){
            max_eq(f[i][j],f[i-1][j]+a[i]*(a[i]==a[i-1]));
            max_eq(f[i][i-1],f[i-1][j]+a[i]*(a[i]==a[j]));
            // printf("%d %d: %lld\n",i,j,f[i][j]);
        }
    }
    ll ans=0;
    for(int j=1;j<n;++j)
        max_eq(ans,f[n][j]);
    printf("%lld\n",ans);
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--) solve();
    return 0;
}
